package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.service.SysUserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private SysUserService sysUserService;
    @PutMapping
    @ApiOperation(value = "用户添加")
    public ResponseResult addUser(@RequestBody UserDto userDto) {
        Boolean result  = sysUserService.addUser(userDto);
        return ResponseResult.success(result);
    }

    @PatchMapping
    @ApiOperation(value = "用户修改")
    public ResponseResult updateUser(@RequestBody UserDto userDto) {
        Boolean result = sysUserService.updateUser(userDto);
        return ResponseResult.success(result);
    }


    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation("用户启用禁用")
    public ResponseResult isEnable(@PathVariable Long id, @PathVariable String status) {
        sysUserService.isEnable(id, status);
        return ResponseResult.success();
    }

    @PutMapping("/list")
    @ApiOperation("用户列表")
    public ResponseResult<List<UserVo>> list(@RequestBody UserDto userDto) {
        List<UserVo> userVo = sysUserService.getUsers(userDto);
        return ResponseResult.success(userVo);
    }

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("用户分页")
    public ResponseResult<PageResponse<UserVo>> page(@PathVariable Integer pageNum,
                                                     @PathVariable Integer pageSize,
                                                     @RequestBody UserDto userDto) {
        PageResponse<UserVo> userVos = sysUserService.getPageUsers(pageNum,pageSize,userDto);
        return ResponseResult.success(userVos);
    }

    @DeleteMapping("/remove/{userIds}")
    @ApiOperation("用户删除")
    public ResponseResult remove(@PathVariable String userIds) {
        sysUserService.deleteUser(userIds);
        return ResponseResult.success();
    }

    @PostMapping("/reset-passwords/{userId}")
    @ApiOperation("重置密码")
    public ResponseResult resetPasswords(@PathVariable Long userId) {
        sysUserService.resetPasswords(userId);
        return ResponseResult.success();
    }

}
